package com.lemon.blog.system.controller;

import com.lemon.blog.system.domain.BlBlog;
import com.lemon.blog.system.service.IBlBlogService;
import com.lemon.common.core.utils.poi.ExcelUtil;
import com.lemon.common.core.web.controller.BaseController;
import com.lemon.common.core.web.domain.AjaxResult;
import com.lemon.common.core.web.page.TableDataInfo;
import com.lemon.common.log.annotation.Log;
import com.lemon.common.log.enums.BusinessType;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import com.lemon.common.security.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 包名称：com.lemon.admin.web.controller.blog
 * 类名称：BlBlogController
 * 类描述：博客controller
 * 创建人：@author huangpeng
 * 创建时间：2022年04月10日 01:01
 */
@Api("博文管理")
@RestController
@RequestMapping("/blog")
public class BlBlogController extends BaseController {

    @Autowired
    private IBlBlogService blBlogService;

    /**
     * 查询博客管理列表
     * @Title: list
     * @Description: 查询博客管理列表
     * @param blBlog
     * @return: TableDataInfo
     * @throws:
     * @author: huangpeng
     * @Date: 2023/2/26 18:34
     */
    @RequiresPermissions("blog:blog:list")
    @GetMapping("/list")
    public TableDataInfo list(BlBlog blBlog) {
        startPage();
        List<BlBlog> list = blBlogService.selectBlBlogList(blBlog);
        return getDataTable(list);
    }

    /**
     * 导出博客列表
     * @Title: export
     * @Description: 导出博客列表
     * @param response
     * @param blBlog
     * @return: void
     * @throws:
     * @author: huangpeng
     * @Date: 2023/2/26 18:34
     */
    @RequiresPermissions("blog:blog:export")
    @Log(title = "博客管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BlBlog blBlog) {
        List<BlBlog> list = blBlogService.selectBlBlogList(blBlog);
        ExcelUtil<BlBlog> util = new ExcelUtil<BlBlog>(BlBlog.class);
        util.exportExcel(response, list, "博客管理数据");
    }

    /**
     * 获取博客管理详细信息
     * @Title: getInfo
     * @Description: 获取博客管理详细信息
     * @param id 博客id
     * @return: AjaxResult
     * @throws:
     * @author: huangpeng
     * @Date: 2023/2/26 18:34
     */
    @RequiresPermissions("blog:blog:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(blBlogService.selectByPrimaryKey(id));
    }

    /**
     * 新增博客
     * @Title: add
     * @Description: 新增博客
     * @param blBlog
     * @return: AjaxResult
     * @throws:
     * @author: huangpeng
     * @Date: 2023/2/26 18:35
     */
    @RequiresPermissions("blog:blog:add")
    @Log(title = "博客管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BlBlog blBlog) {
        return toAjax(blBlogService.insert(blBlog));
    }

    /**
     * 修改博客
     * @Title: edit
     * @Description: 修改博客
     * @param blBlog
     * @return: AjaxResult
     * @throws:
     * @author: huangpeng
     * @Date: 2023/2/26 18:35
     */
    @RequiresPermissions("blog:blog:edit")
    @Log(title = "博客管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BlBlog blBlog) {
        return toAjax(blBlogService.update(blBlog));
    }

    /**
     * 删除博客
     * @Title: remove
     * @Description: 删除博客
     * @param ids 博客id，多个逗号隔开
     * @return: AjaxResult
     * @throws:
     * @author: huangpeng
     * @Date: 2023/2/26 18:36
     */
    @RequiresPermissions("blog:blog:remove")
    @Log(title = "博客管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable("ids") Long[] ids) {
        return toAjax(blBlogService.deleteByBatch(ids));
    }
}
